package ch11_多线程与并发;

class School implements Runnable{
	Thread monitor,tom,teacher;
	public School() {
		monitor = new Thread(this, "班长");
		tom = new Thread(this, "汤姆");
		teacher = new Thread(this, "老师");
	}
	public void teach() {
		monitor.start();
		tom.start();
		teacher.start();
	}
	public void run() {
		Thread th = Thread.currentThread();
		if(th==monitor||th == tom) {
			try {
				System.out.println(th.getName() +": 休息10秒...");
				Thread.sleep(10000);
			}catch(InterruptedException e) {
				System.out.println(th.getName()+"被唤醒了。");
			}
			System.out.println(th.getName() +":老师好！");
			tom.interrupt();
		}else if(th ==teacher) {
			for(int i= 0; i<3;i++) {
				System.out.println(th.getName()+": 上课！");
				try {
					Thread.sleep(500);
				}catch(InterruptedException e) {

				}
			}
			monitor.interrupt();
		}
	}
}
public class InterruptDemo {
	public static void main(String[] args) {
		new School().teach();
	}
}
